// processor definitions
//#include "lm4f120h5qr.h"

#include "inc/hw_gpio.h"
#include "inc/hw_memmap.h"
#include "inc/hw_sysctl.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"

#define PB_5 GPIO_PIN_5
#define PB_0 GPIO_PIN_0
#define PB_1 GPIO_PIN_1
#define PE_4 GPIO_PIN_4
#define PE_5 GPIO_PIN_5
#define PB_4 GPIO_PIN_4
#define PA_5 GPIO_PIN_5
#define PA_6 GPIO_PIN_6
#define PA_7 GPIO_PIN_7

int delay(int time);

int main(void) {

	//enable clock
	ROM_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);

	// enable PORT B,E,A GPIO peripheral
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB | SYSCTL_PERIPH_GPIOE | SYSCTL_PERIPH_GPIOA);

	// set LED PORT B,E,A pins as outputs
	ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, (PB_5 | PB_0 | PB_1 | PB_4));
	ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, (PE_4 | PE_5));
	ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, (PA_5 | PA_6 | PA_7));

	//write to pins
	ROM_GPIOPinWrite(GPIO_PORTB_BASE, PB_5, 0);
	ROM_GPIOPinWrite(GPIO_PORTB_BASE, PB_0, 0);
	ROM_GPIOPinWrite(GPIO_PORTB_BASE, PB_1, 0);
	ROM_GPIOPinWrite(GPIO_PORTE_BASE, PE_4, 0);
	ROM_GPIOPinWrite(GPIO_PORTE_BASE, PE_5, 0);
	ROM_GPIOPinWrite(GPIO_PORTB_BASE, PB_4, 0);
	ROM_GPIOPinWrite(GPIO_PORTA_BASE, PA_5, 0);
	ROM_GPIOPinWrite(GPIO_PORTA_BASE, PA_6, 0);
	ROM_GPIOPinWrite(GPIO_PORTA_BASE, PA_7, 0);

	// loop forever
	for(;;)
	{
		ROM_GPIOPinWrite(GPIO_PORTB_BASE, PB_5, 32);
		delay(2);
		ROM_GPIOPinWrite(GPIO_PORTB_BASE, PB_5, 0);

		ROM_GPIOPinWrite(GPIO_PORTB_BASE, PB_0, 1);
		delay(2);
		ROM_GPIOPinWrite(GPIO_PORTB_BASE, PB_0, 0);
		
		ROM_GPIOPinWrite(GPIO_PORTB_BASE, PB_1, 2);
		delay(2);
		ROM_GPIOPinWrite(GPIO_PORTB_BASE, PB_1, 0);
		
		ROM_GPIOPinWrite(GPIO_PORTE_BASE, PE_4, 16);
		delay(2);
		ROM_GPIOPinWrite(GPIO_PORTE_BASE, PE_4, 0);
		
		ROM_GPIOPinWrite(GPIO_PORTE_BASE, PE_5, 32);
		delay(2);
		ROM_GPIOPinWrite(GPIO_PORTE_BASE, PE_5, 0);
		
		ROM_GPIOPinWrite(GPIO_PORTB_BASE, PB_4, 16);
		delay(2);
		ROM_GPIOPinWrite(GPIO_PORTB_BASE, PB_4, 0);
		
		ROM_GPIOPinWrite(GPIO_PORTA_BASE, PA_5, 32);
		delay(2);
		ROM_GPIOPinWrite(GPIO_PORTA_BASE, PA_5, 0);
		
		ROM_GPIOPinWrite(GPIO_PORTA_BASE, PA_6, 64);
		delay(2);
		ROM_GPIOPinWrite(GPIO_PORTA_BASE, PA_6, 0);
		
		ROM_GPIOPinWrite(GPIO_PORTA_BASE, PA_7, 128);
		delay(2);
		ROM_GPIOPinWrite(GPIO_PORTA_BASE, PA_7, 0);
		
		//delay(2);
	}
}

int delay(int time)
{
	ROM_SysCtlDelay(time*500000*2);
	
	return 0;
}
